package academic.ui.client.widgets;

import java.util.ArrayList;

import ui.client.GenericClickable;
import ui.client.GenericContainerTag;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Image;

import ecommerce.soco.shared.GWT_Product;

public class SlideDealsGraph extends Composite {

	private GenericContainerTag div = new GenericContainerTag("div");
	private GenericContainerTag items = new GenericContainerTag("div");
	private GenericClickable back = new GenericClickable("a");
	private GenericClickable next = new GenericClickable("a");
	private GenericContainerTag wizard = new GenericContainerTag("div");
	private ArrayList<HasClickHandlers> productImageClick=new ArrayList<HasClickHandlers>();
	
	public SlideDealsGraph() {
		div.setStyleName("recentDealsSlide");
		div.add(back);
		div.add(wizard);
		wizard.add(items);
		wizard.setStyleName("tooltipWizard");
		wizard.addStyleName("recentDealstoolTipWizard");
		div.add(next);
		back.setVisible(false);
		next.setVisible(false);
		back.setStyleName("prev");
		next.setStyleName("next");
		items.setStyleName("items");
		initWidget(div);
	}

	public void setup(ArrayList<GWT_Product> products) {
		items.clear();
		productImageClick.clear();
		for(int i=0; i<products.size();i+=2) {
			GenericContainerTag page = new GenericContainerTag("div");
			items.add(page);
			for(int j=i;j<i+2 && j<products.size();j++) {
				Image img = new Image(GWT.getModuleBaseURL()+"../PICS/Merchants/"+products.get(j).getMerchant().getImage());
				img.getElement().setId(String.valueOf(products.get(j).getId()));
				productImageClick.add(img);
				img.setSize("100px","100px");
				page.add(new BoughtPriceDiv(products.get(j)));
				page.add(img);
			}
		}
	}
	
	public ArrayList<HasClickHandlers> productImageClickables() {
		return productImageClick;
	}
}
